package com.shujia.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo3MakeRDD {
  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf()
      .setAppName("make")
      .setMaster("local")


    val sc = new SparkContext(conf)



    //1 读取文件构建RDD

    /**
      * 1  如果是本地运行, 读取的文件是本地文件
      *
      * 2 如果是集群运行,读取的文件是hdfs文件
      *
      */

    val rdd: RDD[String] = sc.textFile("spark/data/students.txt")

    rdd.foreach(println)


    //2\ 通过scala集合构建RDD
    val rdd2: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5, 6, 7, 8, 9))


    rdd2.filter(i => i % 2 == 1).foreach(println)

  }

}
